/**
 * ****************************************************************************
 * Project: RoboBridge
 * ----------------------------------------------------------------------------
 * -------------------------- [c]2012 - KrawallMann ---------------------------
 * ---------------------- http://www.krawallmann.de.tc/ -----------------------
 * ****************************************************************************
 * File: WLANRemoteDevice.java Package:
 * tc.de.krawallmann.robobridge.communication.lan.wlan Version: 1.0 Author(s):
 * KrawallMann
 * ****************************************************************************
 * Description:
 * ****************************************************************************
 */
package tc.de.krawallmann.robobridge.communication.lan.wlan;

import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.Set;

import tc.de.krawallmann.robobridge.communication.lan.LANRemoteDevice;

/**
 * The Class WLANRemoteDevice represents a device available on the WLAN.
 * 
 * @author KrawallMann
 * @version 1.0
 */
public class WLANRemoteDevice extends LANRemoteDevice {

	/** The listeners. */
	private transient final Set<RSSIListener> listeners = new HashSet<RSSIListener>();

	/** The rssi. */
	private int rssi;

	/**
	 * Instantiates a new WLAN remote device.
	 */
	public WLANRemoteDevice() {
		super();
	}

	/**
	 * Instantiates a new WLAN remote device.
	 * 
	 * @param deviceIP
	 *            the device ip
	 * @param port
	 *            the port
	 * @throws UnknownHostException
	 *             the unknown host exception
	 */
	public WLANRemoteDevice(final String deviceIP, final int port) throws UnknownHostException {
		super(deviceIP, port);
	}

	/**
	 * Instantiates a new WLAN remote device.
	 * 
	 * @param deviceIP
	 *            the device ip
	 * @param port
	 *            the port
	 * @param name
	 *            the name
	 * @throws UnknownHostException
	 *             the unknown host exception
	 */
	public WLANRemoteDevice(final String deviceIP, final int port, final String name)
			throws UnknownHostException {
		super(deviceIP, port, name);
	}

	/**
	 * Adds the rssi listener.
	 * 
	 * @param listener
	 *            the listener
	 * @return true, if successful
	 */
	public boolean addRSSIListener(final RSSIListener listener) {
		return listeners.add(listener);
	}

	/**
	 * Clear rssi listeners.
	 */
	public void clearRSSIListeners() {
		listeners.clear();
	}

	/**
	 * Gets the rssi (Received Signal Strength Indication).
	 * 
	 * @return the rssi
	 */
	public int getRssi() {
		return rssi;
	}

	/**
	 * Removes the rssi listener.
	 * 
	 * @param listener
	 *            the listener
	 * @return true, if successful
	 */
	public boolean removeRSSIListener(final RSSIListener listener) {
		return listeners.remove(listener);
	}

	/**
	 * Sets the rssi (Received Signal Strength Indication).
	 * 
	 * @param rssi
	 *            the new rssi
	 */
	protected void setRssi(final int rssi) {
		this.rssi = rssi;
		for (final RSSIListener l : listeners) {
			l.onRSSIUpdated(rssi);
		}
	}
}
